<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;


class ConfigController extends CommonController
{

    public function index()
    {
        //$list = \DB::table('config')->get();
        $list = \DB::table('config')->get();
	
       
        //return view('config.index',['list'=>[]]);
         return view('admin.config.index',["list"=>$list[0]]);
       // return view('config.index', compact('list'));
	   
    }
	
     public function edit(Request $request,$id)
    {   

        $list = \DB::table("config")->where("id",$id)->get();
		return view("admin.config.edit",["list"=>$list[0]]);
        
    }
    public function update(Request $request,$id)
    {
		$filename = $request->filename;
        //except()
        $content=$request->except('_token','id');
				//上传图片       
        //判断是否有上传文件
        if($request->hasFile('ufile')) {
            //获取上文件信息
            $file = $request->file('ufile');
            //获取上传文件的后缀名
            $ext = $file->getClientOriginalExtension();
            //随机一个新的文件名
            $filename = time().rand(1000,9999).".".$ext;
            //执行文件移动
            $newfile = $file->move("./uploads/",$filename);
            $path = public_path();
            $lan = "/uploads/".$filename;

        }
		
        //获取要修改的数据
        // $data = $request->update("name",'keywords','copyright','logo','status');var_dump($data);die;
        // array_set($data, 'ufile', $lan);

		//dd($request);
        $id = \DB::table("config")->where('id',$id)->update(['name'=>$request->name,'keywords'=>$request->keywords,'logo'=>$filename,'status'=>$request->status]);
        //判断
		if($id>0){
			$info = "网站配置修改成功！";
        }else{ 
			$info = "网站配置修改失败！";
        }
		return view("admin.config.info",['info'=>$info]);
        
    }

    public function destroy($id)
    {
		return redirect("admin/config")->with('error',$info);
    }
}
